package cc.rengu.igas.momp.biz.service.impl;


import cc.rengu.igas.momp.common.enums.MompTxnNumEnum;
import cc.rengu.igas.momp.common.enums.RespCodeEnum;
import cc.rengu.igas.momp.facade.QueryMcDetailInfoService;
import cc.rengu.igas.momp.facade.request.*;
import cc.rengu.igas.momp.facade.response.*;
import cc.rengu.igas.momp.facade.result.Result;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.DubboResult;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;

/**
 * 营销活动详情查询接口实现
 *
 * @author Jinan Liu
 * @version 1.0.0
 * @date 2020/3/16 09:58
 */
@SuppressWarnings("unchecked")
public class QueryMcDetailInfoServiceImpl implements QueryMcDetailInfoService {

    /**
     * 代理商营销活动详情查询接口Dubbo实现
     *
     * @param queryAgentProfitSharingMcDetailInfoRequest 代理商分润类活动详情查询接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryAgentProfitSharingMcDetailInfoResponse> 代理商分润类活动详情查询接口应答对象
     * @author Jinan Liu
     * @date 2020/5/28 14:45
     */
    @Override
    public Result<QueryAgentProfitSharingMcDetailInfoResponse> queryAgentProfitSharingMcDetailInfo(QueryAgentProfitSharingMcDetailInfoRequest queryAgentProfitSharingMcDetailInfoRequest) {

        DubboService<QueryAgentProfitSharingMcDetailInfoRequest> dubboService = new DubboServiceImpl();
        Result<QueryAgentProfitSharingMcDetailInfoResponse> queryAgentProfitSharingMcDetailInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_APS_MC_DETAIL.getTxnNum().equals(queryAgentProfitSharingMcDetailInfoRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryAgentProfitSharingMcDetailInfoResponse> dubboResult = dubboService.callAtomService(queryAgentProfitSharingMcDetailInfoRequest,
                    MompTxnNumEnum.QUERY_APS_MC_DETAIL.getService(), QueryAgentProfitSharingMcDetailInfoResponse.class);
            queryAgentProfitSharingMcDetailInfoResponseResult.setResult(dubboResult.getResult());
            queryAgentProfitSharingMcDetailInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            QueryAgentProfitSharingMcDetailInfoResponse queryAgentProfitSharingMcDetailInfoResponse = new QueryAgentProfitSharingMcDetailInfoResponse();
            queryAgentProfitSharingMcDetailInfoResponseResult.setResult(queryAgentProfitSharingMcDetailInfoResponse);
            queryAgentProfitSharingMcDetailInfoResponse.setHeader(queryAgentProfitSharingMcDetailInfoRequest.getHeader());
            queryAgentProfitSharingMcDetailInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryAgentProfitSharingMcDetailInfoResponse.setRespCode(((BizException) e).getCode());
                queryAgentProfitSharingMcDetailInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryAgentProfitSharingMcDetailInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryAgentProfitSharingMcDetailInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return queryAgentProfitSharingMcDetailInfoResponseResult;
    }

    /**
     * 收银员返现营销活动详情查询接口Dubbo实现
     *
     * @param queryCashierCashbackMcDetailInfoRequest 收银员返现类活动详情查询接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryCashierCashbackMcDetailInfoResponse> 收银员返现类活动详情查询接口应答对象
     * @author Jinan Liu
     * @date 2020/5/28 14:44
     */
    @Override
    public Result<QueryCashierCashbackMcDetailInfoResponse> queryCashierCashbackMcDetailInfo(QueryCashierCashbackMcDetailInfoRequest queryCashierCashbackMcDetailInfoRequest) {

        DubboService<QueryCashierCashbackMcDetailInfoRequest> dubboService = new DubboServiceImpl();
        Result<QueryCashierCashbackMcDetailInfoResponse> queryCashierCashbackMcDetailInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_CCB_MC_DETAIL.getTxnNum().equals(queryCashierCashbackMcDetailInfoRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryCashierCashbackMcDetailInfoResponse> dubboResult = dubboService.callAtomService(queryCashierCashbackMcDetailInfoRequest,
                    MompTxnNumEnum.QUERY_CCB_MC_DETAIL.getService(), QueryCashierCashbackMcDetailInfoResponse.class);
            queryCashierCashbackMcDetailInfoResponseResult.setResult(dubboResult.getResult());
            queryCashierCashbackMcDetailInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            QueryCashierCashbackMcDetailInfoResponse queryCashierCashbackMcDetailInfoResponse = new QueryCashierCashbackMcDetailInfoResponse();
            queryCashierCashbackMcDetailInfoResponseResult.setResult(queryCashierCashbackMcDetailInfoResponse);
            queryCashierCashbackMcDetailInfoResponse.setHeader(queryCashierCashbackMcDetailInfoRequest.getHeader());
            queryCashierCashbackMcDetailInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryCashierCashbackMcDetailInfoResponse.setRespCode(((BizException) e).getCode());
                queryCashierCashbackMcDetailInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryCashierCashbackMcDetailInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryCashierCashbackMcDetailInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return queryCashierCashbackMcDetailInfoResponseResult;
    }

    /**
     * 卡券营销活动详情查询接口Dubbo实现
     *
     * @param queryCouponMcDetailInfoRequest 卡券类活动详情查询接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryCouponMcDetailInfoResponse> 卡券类活动详情查询接口应答对象
     * @author Jinan Liu
     * @date 2020/5/28 14:44
     */
    @Override
    public Result<QueryCouponMcDetailInfoResponse> queryCouponMcDetailInfo(QueryCouponMcDetailInfoRequest queryCouponMcDetailInfoRequest) {

        DubboService<QueryCouponMcDetailInfoRequest> dubboService = new DubboServiceImpl();
        Result<QueryCouponMcDetailInfoResponse> queryCouponMcDetailInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_CP_MC_DETAIL.getTxnNum().equals(queryCouponMcDetailInfoRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryCouponMcDetailInfoResponse> dubboResult = dubboService.callAtomService(queryCouponMcDetailInfoRequest,
                    MompTxnNumEnum.QUERY_CP_MC_DETAIL.getService(), QueryCouponMcDetailInfoResponse.class);
            queryCouponMcDetailInfoResponseResult.setResult(dubboResult.getResult());
            queryCouponMcDetailInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            QueryCouponMcDetailInfoResponse queryCouponMcDetailInfoResponse = new QueryCouponMcDetailInfoResponse();
            queryCouponMcDetailInfoResponseResult.setResult(queryCouponMcDetailInfoResponse);
            queryCouponMcDetailInfoResponse.setHeader(queryCouponMcDetailInfoRequest.getHeader());
            queryCouponMcDetailInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryCouponMcDetailInfoResponse.setRespCode(((BizException) e).getCode());
                queryCouponMcDetailInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryCouponMcDetailInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryCouponMcDetailInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return queryCouponMcDetailInfoResponseResult;
    }

    /**
     * 商户手续费减免营销活动详情查询接口Dubbo实现
     *
     * @param queryMchntFeeDiscountMcDetailInfoRequest 商户手续费减免类活动详情查询接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryMchntFeeDiscountMcDetailInfoResponse> 商户手续费减免类活动详情查询接口应答对象
     * @author Jinan Liu
     * @date 2020/5/28 14:44
     */
    @Override
    public Result<QueryMchntFeeDiscountMcDetailInfoResponse> queryMchntFeeDiscountMcDetailInfo(QueryMchntFeeDiscountMcDetailInfoRequest queryMchntFeeDiscountMcDetailInfoRequest) {

        DubboService<QueryMchntFeeDiscountMcDetailInfoRequest> dubboService = new DubboServiceImpl();
        Result<QueryMchntFeeDiscountMcDetailInfoResponse> queryMchntFeeDiscountMcDetailInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_MFD_MC_DETAIL.getTxnNum().equals(queryMchntFeeDiscountMcDetailInfoRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryMchntFeeDiscountMcDetailInfoResponse> dubboResult = dubboService.callAtomService(queryMchntFeeDiscountMcDetailInfoRequest,
                    MompTxnNumEnum.QUERY_MFD_MC_DETAIL.getService(), QueryMchntFeeDiscountMcDetailInfoResponse.class);
            queryMchntFeeDiscountMcDetailInfoResponseResult.setResult(dubboResult.getResult());
            queryMchntFeeDiscountMcDetailInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            QueryMchntFeeDiscountMcDetailInfoResponse queryMchntFeeDiscountMcDetailInfoResponse = new QueryMchntFeeDiscountMcDetailInfoResponse();
            queryMchntFeeDiscountMcDetailInfoResponseResult.setResult(queryMchntFeeDiscountMcDetailInfoResponse);
            queryMchntFeeDiscountMcDetailInfoResponse.setHeader(queryMchntFeeDiscountMcDetailInfoRequest.getHeader());
            queryMchntFeeDiscountMcDetailInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryMchntFeeDiscountMcDetailInfoResponse.setRespCode(((BizException) e).getCode());
                queryMchntFeeDiscountMcDetailInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryMchntFeeDiscountMcDetailInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryMchntFeeDiscountMcDetailInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return queryMchntFeeDiscountMcDetailInfoResponseResult;
    }

    /**
     * 减免类营销活动详情查询接口Dubbo实现
     *
     * @param queryMoneyOffMcDetailInfoRequest 减免类活动详情查询接口请求报文
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryMoneyOffMcDetailInfoResponse> 减免类活动详情查询接口应答报文
     * @author Jinan Liu
     * @date 2020/5/28 14:43
     */
    @Override
    public Result<QueryMoneyOffMcDetailInfoResponse> queryMoneyOffMcDetailInfo(QueryMoneyOffMcDetailInfoRequest queryMoneyOffMcDetailInfoRequest) {

        DubboService<QueryMoneyOffMcDetailInfoRequest> dubboService = new DubboServiceImpl();
        Result<QueryMoneyOffMcDetailInfoResponse> queryMoneyOffMcDetailInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_MO_MC_DETAIL.getTxnNum().equals(queryMoneyOffMcDetailInfoRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryMoneyOffMcDetailInfoResponse> dubboResult = dubboService.callAtomService(queryMoneyOffMcDetailInfoRequest,
                    MompTxnNumEnum.QUERY_MO_MC_DETAIL.getService(), QueryMoneyOffMcDetailInfoResponse.class);
            queryMoneyOffMcDetailInfoResponseResult.setResult(dubboResult.getResult());
            queryMoneyOffMcDetailInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            QueryMoneyOffMcDetailInfoResponse queryMoneyOffMcDetailInfoResponse = new QueryMoneyOffMcDetailInfoResponse();
            queryMoneyOffMcDetailInfoResponseResult.setResult(queryMoneyOffMcDetailInfoResponse);
            queryMoneyOffMcDetailInfoResponse.setHeader(queryMoneyOffMcDetailInfoRequest.getHeader());
            queryMoneyOffMcDetailInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryMoneyOffMcDetailInfoResponse.setRespCode(((BizException) e).getCode());
                queryMoneyOffMcDetailInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryMoneyOffMcDetailInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryMoneyOffMcDetailInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return queryMoneyOffMcDetailInfoResponseResult;
    }

    /**
     * 营销活动详情-商户/用户查询接口Dubbo实现
     *
     * @param queryMcMerUserListRequest 营销活动详情商户/用户查询接口请求报文
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryMoneyOffMcDetailInfoResponse> 减免类活动详情查询接口应答报文
     * @author liujinan
     * @date 2021/4/19 14:43
     */
    @Override
    public Result<QueryMcMerUserListInfoResponse> queryMcMerUserList(QueryMcMerUserListRequest queryMcMerUserListRequest) {
        DubboService<QueryMcMerUserListRequest> dubboService = new DubboServiceImpl();
        Result<QueryMcMerUserListInfoResponse> queryMcMerUserListInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_MC_MER_USER_LIST.getTxnNum().equals(queryMcMerUserListRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryMcMerUserListInfoResponse> dubboResult = dubboService.callAtomService(queryMcMerUserListRequest,
                    MompTxnNumEnum.QUERY_MC_MER_USER_LIST.getService(), QueryMcMerUserListInfoResponse.class);
            queryMcMerUserListInfoResponseResult.setResult(dubboResult.getResult());
            queryMcMerUserListInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {
            QueryMcMerUserListInfoResponse queryMcMerUserListInfoResponse = new QueryMcMerUserListInfoResponse();
            queryMcMerUserListInfoResponseResult.setResult(queryMcMerUserListInfoResponse);
            queryMcMerUserListInfoResponse.setHeader(queryMcMerUserListRequest.getHeader());
            queryMcMerUserListInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryMcMerUserListInfoResponse.setRespCode(((BizException) e).getCode());
                queryMcMerUserListInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryMcMerUserListInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryMcMerUserListInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }
        return queryMcMerUserListInfoResponseResult;
    }

    /**
     * 营销活动详情-商户列表查询接口
     *
     * @param queryMcMerListRequest
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryMcMerListInfoResponse>
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/6/28 19:13
     */
    @Override
    public Result<QueryMcMerListInfoResponse> queryMcMerList(QueryMcMerListRequest queryMcMerListRequest) {

        DubboService<QueryMcMerListRequest> dubboService = new DubboServiceImpl();
        Result<QueryMcMerListInfoResponse> queryMcMerListInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_MC_MER_LIST.getTxnNum().equals(queryMcMerListRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryMcMerListInfoResponse> dubboResult = dubboService.callAtomService(queryMcMerListRequest,
                    MompTxnNumEnum.QUERY_MC_MER_LIST.getService(), QueryMcMerListInfoResponse.class);

            queryMcMerListInfoResponseResult.setResult(dubboResult.getResult());
            queryMcMerListInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {
            QueryMcMerListInfoResponse queryMcMerListInfoResponse = new QueryMcMerListInfoResponse();
            queryMcMerListInfoResponseResult.setResult(queryMcMerListInfoResponse);
            queryMcMerListInfoResponse.setHeader(queryMcMerListRequest.getHeader());
            queryMcMerListInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryMcMerListInfoResponse.setRespCode(((BizException) e).getCode());
                queryMcMerListInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryMcMerListInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryMcMerListInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }
        return queryMcMerListInfoResponseResult;
    }

}
